package com.htl.集合;

import java.util.Iterator;
import java.util.Set;
import java.util.TreeMap;

/**
 *  TreeMap 中存储有序的元素，存入的元素会自动进行排序，按照 key 值进行升序排列。
 */

public class TreeMap__test {
    public static void main(String[] args) {
        TreeMap treeMap = new TreeMap();

        treeMap.put(3, "Java");
        treeMap.put(5, "JavaME");
        treeMap.put(1,"Hello");
        treeMap.put(6, "JavaEE");
        treeMap.put(2, "World");
        treeMap.put(4, "JavaSE");

//        treeMap.put("a", "Java");
//        treeMap.put("e", "JavaME");
//        treeMap.put("c","Hello");
//        treeMap.put("d", "JavaEE");
//        treeMap.put("b", "World");
//        treeMap.put("f", "JavaSE");

        Set keySet = treeMap.keySet();
        Iterator iterator = keySet.iterator();
        while (iterator.hasNext()) {
            Object key = iterator.next();
            System.out.println(key + "---" + treeMap.get(key));
        }
    }
}
